welcome to another module data visualization as we Learned it is useful to get statistic understanding of your data however it is hard to digest that many number at the same time as also when you talk to different audience stats or numbers are not that friendly to those people who are not the expert in this field so data visualization can help you to effectively and efficiently communicate with all kinds of audience and we are going to spend 3 modules to learn how to do data visualization this module we are going to learn how to do that from data frame directly next module we're going to learn how to do Data Visualization by Matplotlib and the last one we're going to do Data Visualization with the seaborn then you will have sufficient tools for you to do the data visualization you like for your data set let's first look at the setup so we are going to rely on the must-two packages we have played so many times import numpy as np and import pandas as pd then we're going to load the dataset now you know that the dataset I have already uploaded into the file part which is Economy_of_US.csv you can find this CSV file in our module and download it then upload it to this place and then you know read the CSV basically will give you what is the performance of the US economy and we have the data from 1980 that is the year up to the data we have here is 2027 as some estimation and we can see that our data has the GDP_PPP which is one measurement of the GDP the other one is GDP_Nominal and that is another evaluation of the GDP and also we have the GDP per capita and the GDP growth and the inflation unemployment and also inflation change so on and so forth so that will be our sample data to play with for this example okay so before we move on we need to get a big picture for our dataset first so that will be the df.info(), that is always we are going to do so we basically has only 48 entries because that is the years of the performance and we have only 9 different columns and we have the year as integer and we have all the other most of the others are in float which means that we can do a lot of things with those numeric attributes and for that describe() they are going to do again give us a big picture of the statistical understanding for those numeric attributes so that will be the first step we have the database set up we have the packages ready and then we are ready to move on to visualize them the most straightforward one is the scatter it's like point to point. In order to show a scatter we have to project our data points in 2D place that is we have the XS and we have the YS in this case we are going to use the years as the axis because that represents the time and we are going to use the YS to indicate inflation so each data point as you can see here are mapped onto a dot in this 2D dimension this dot basically means that in 1980 we have a really high inflation so this shows up the relationship between the ear and the inflation and you can change the attributes or x's and y's into different attributes to play with this scatter plot so this is one default one this is the one most commonly you can see to show the relationship between 2 attributes and the x is straightforward and the y is also straightforward the other one is the kind because we call the df.plot(), which is a very general function so if you want pandas to know which exactly plot you are going to show you can specify the kind as a scatter so we are going to show the relationship in terms of the dots and we can do some other plots as well in this case we can see that the y equal to inflation has the kind as line so you will see that the x-axis is actually 0-40 that is corresponding to our indexes remember we have around 47 rows of our data so this 0 and a 40 represents that label of the indexes and the y is our inflation as we specified here so here we can show along with the time because we ordered our dataset in terms of the year what is the change of inflation so that will give us the curve of the change along the time and give us the variance of the inflation and in here you can you can in here you can see that if you do not specify the axis by default it will be the index label and you can see we can specify the kind equity line to specify we want a line plot rather than a scatter plot you can also specify X and y together in this case it will be more explicit that our XS or ears and the y is the inflation and the kind is line and then we can see here even we have a small legend to show what this line represents as inflation the area plus is also very useful if we want to show the accumulation of some numbers such as the sales such as the profit such as the quantity etc then we can use for example in this case we show the GDP use the areas we can see clearly this is a thing increasing significantly over the years and if you are going to show the area you have to specify you are going to have the kind as area and then we can also do the bar charts, for the bar charts they're not going to show like one shape in the area but also they are going to show them in a isolated bar so that it will be more explicit that this bar represents the value of this particular year so rather than focusing on the trend from this year to this year you can make a comparison that this year actually has a decrement of the GDP for this year we have something happen that is not happy so this will be the thing you can show by the bar plot again you need to specify the x and the y and then and also have the kind equal to bar that will be sufficient you can also call df.plot() with the bar with horizontal way to show them so that you have the 2027 at the first line and then you have the 1980 as the last line so you can also do a comparison but this time is horizontally because we have the bar horizontal specified okay so so far we have learned how to represent the relationship or the trend of our different attributes in a plot, let's see some other ones for example histogram histogram can call from one attribute directly so it is not call from df, but the call from df['inflation'] column because the histogram plot we specify as kind as hist is because we want to know the distribution of your data in terms of the count or in terms of the frequency the x by default will be the value that is the inflation value so we have 0.0 and we have 0.14 and the wise will be the percentage we can see this value for example, the 0.0 we only see less than 2% the 0.14 is only less than 2% as well which are really rare and you can see the really high bar in this area shows that the 0.02 is actually very common more than 17% and a 0.03 is also a very common inflation we can see around 16% because that is what the Fed wants right we always control the information in that range so the histogram can help you to know how your value appears in terms of the frequency by default you will see that we have limited bars and we call that bins because we basically count how many value into this bin then we increment the count in this bin we can even specify the bin to be more such as 100 in this case you will see a more detailed bar chart of the histogram chart of the inflation and you can see that this 0.00 is actually only 1% or just one count and for here it is also very small so on and so forth and this is a very high bar just that the frequency is really high so the more bins you have the more detailed information you are going to have or the more flattened the frequency count you may have because you have more details of each of the bin basically we can have a look on the unemployment attribute as well for the histogram so we can see that the 0.05 has the highest frequency of unemployment in the states and the other way to show the distribution rather than the histogram like this bar is we can have a more smooth curve and we need to specify that as a kde the KDE is a density based estimation of your distribution so that we can translate this bar into a curve and that curve shows a little bit different aspect of your distribution but actually they are basically the same thing now we can also do the box plot so the box plot actually can show you how the dispersion and how the central tendency of your data set can be first of all let's focus on this box this is exactly a box the middle the green line is your median or your Q2 and this bottom border of the box is your Q1 and upper border of your box is your Q3 so we actually have the Q1, Q2 and the Q3 form that box once we have this Q1 and Q3 we are going to have our IQR, Inter Quantile Range that is Q3 - Q1 once we have that we can use Q3+1.5* IQR to get this bar this bar represents the theoretical upper or maximum of your data anything beyond of this bar, as these dots will be regarded as abnormal or will be as rare or will be as outliers we are going to use the IQR, same thing to the lower boundwhich is Q1 in Q1 we are going to minus 1.5 IQR then we are going to get this part so this point will be the theoretical minimum of your normal data which means any data less than this theoretical minimum will be outliers that is why we find this dot so the box plot actually very helpful for you to know both central tendency and dispersion and also help you detect possible outliers in terms of the statistics we can see that the unemployment box plot is much nicer than inflation's because the unemployment basically we can see from this box plot has no outlier basically means that they are all regarded as normal data we can see the other one is for the pie because we learned that for the categorical data attributes we want to know what is the portion of each of the label and we do have one that is the inflation change in inflation change we can do the value counts and we can see that in so many years we actually has around half of them decrease another half of them increase and they have 3 as no change we can use a pie plot to show the portion of each of the label easily we simply call from the value_ccounts() which is a data frame or series itself and then we go from here and call plot() and the kind equal to pie so we are going to see these colorful pie out there and we can see the increase and the decrease they have larger portion than the no change the last part is the color map as we know that for the scatter we can only show the relationship between 2 attributes how about if we want to have the 3rd dimension into our plot then we must call from scatter() directly so previously we all just call from plot() that is a very general call will give you a very general result however if you want to call a very specified plot such as a scatter plot to fit in a very specified argument called color then you must call from the scatter plot rather than call from plot and call it kind is scatter so when you come from scatter plot it provides you more flexibility for these specified arguments such as c='unemployment' in this case we still have the x and y as the scatter which is the same as we see in the first picture however because we have the c as a specified argument the unemployment as a rate we can show the color bar on the right side of your plot actually can use the different color to represent the level of your unemployment the lower the unemployment is, the darker or the blue your color can be the lighter the color represents the higher of your unemployment so in this 2D plot because we have the coloring we actually can get the 3rd dimension into interpretation which is very colorful of course and also can give you more information when you do this visualization the last report I want to show you as always is the documentation so you can go to the pydata.org for the pandas detailed information of the data frame plot and also you can see some other user guide for the visualization use pandas directly have a happy learning I will see you later on